package com.acme;

import com.acme.bankapp.domain.account.CheckingAccount;
import com.acme.bankapp.domain.account.SavingAccount;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.exception.BankExeption;
import com.acme.bankapp.service.bank.AccountID;
import com.acme.bankapp.service.bank.BankService;
import com.acme.bankapp.service.bank.Gender;

public class BankApplication {
	public void modifyBank(Bank bank) {
		try {
			bank.getClient(0).getAcc().withdraw(3000);
		} catch (BankExeption e) {
			System.err.println("Illegal value: " + e.getAmount());
		}
		try {
			bank.getClient(1).getAcc().withdraw(303);
		} catch (BankExeption e) {
			System.err.println("Invalid query");
		}

	}

	public static void main(String[] args) {
		Bank bank = new Bank();
		BankApplication bapp = new BankApplication();
		BankService bankserv = new BankService();

		Client cl1 = new Client("Petrov", Gender.MALE, 45);
		Client cl2 = new Client("Petrova", Gender.FEMALE, 45);

		cl1.addAcc(new SavingAccount(AccountID.set(),2000));
		cl2.addAcc(new CheckingAccount(AccountID.set(),2000, 3056));

		try {
			bankserv.addClient(bank, cl1);
		} catch (Exception ex) {

		}
		try {
			bankserv.addClient(bank, cl2);
		} catch (Exception ex) {

		}

		// test block
		// eguals()
		
//		System.out.println();
//		for (Account ac:cl1.getAccList()){
//			System.out.print(ac);
//		}
		
		System.out.print("Client1 == Client2?: ");
		System.out.println(bank.getClient(0)==bank.getClient(1));
		System.out.print("Account1 == Account2?: ");
		System.out.println(bank.getClient(0).getAcc().equals(new SavingAccount(AccountID.set(),2000)));
		bapp.modifyBank(bank);
		System.out.print("Account1 == Account2? after change: ");
		System.out.println(bank.getClient(0).getAcc().equals(bank.getClient(1).getAcc()));
		// toString()
		System.out.println(bank.getClient(0));
		System.out.println(bank.getClient(1));
	}
}
